<?php

namespace Home\Controller;

/**
 * Description of MemberController
 *
 * @author 阿明 symphp@foxmail.com
 */
class MemberController extends \Think\Controller{
    /**
     * 存储模型对象.
     * @var \Home\Model\MemberModel 
     */
    private $_model = null;

    /**
     * 设置标题和初始化模型.
     */
    protected function _initialize() {
        $meta_titles  = array(
            'index'  => '重庆京西上传',
            'register'    => '用户注册',
            'edit'   => '修改商品分类',
            'delete' => '删除商品分类',
        );
        $meta_title   = isset($meta_titles[ACTION_NAME])?$meta_titles[ACTION_NAME]:'京西商城';
        $this->assign('meta_title', $meta_title);
        $this->_model = D('Member');
    }
    /**
     * 显示注册页面
     */
    public function regist(){
        if(IS_POST){
            //收集数据
            if($this->_model->create()===false){
                $this->error(get_error($this->_model->getError()));
            }
            if($this->_model->addMember()===false){
                $this->error(get_error($this->_model->getError()));
            };
            $this->success('添加成功');
        }else{
        //渲染视图    
        $this->display();
        }
    }
    
    /**
     * 验证用户名 邮箱 手机号码是否注册
     */
    public function checkInfo(){
        $cond = I('get.');
        if($cond){
            if($this->_model->where($cond)->count()){
                $this->ajaxReturn(false);
            }
        }
        $this->ajaxReturn(true);
    }
    
    /**
     * 发送短信验证码
     */
    public function sendSMS($telphone){
        //随机生成验证码
        $code = \Org\Util\String::randNumber(1000, 9999);
        //存入session进行验证
        session('TEL_CAPTCHA',$code);
        //调用发送短信接口
        if(sendSMS($telphone,['code'=>(string)$code,'product'=>'测试哈哈'])){
            return $this->success('发送成功');
        }else{
            return $this->error('发送失败');  
        };
    }
    
    public function ss(){
        $this->_model->aa();
    }
}
